﻿using System;
using System.Linq;

namespace Z.IconLibraryGenerator.WinForm
{
    public partial class ApplicationConfiguration
    {
        /// <summary>Saves a project.</summary>
        /// <param name="projectConfiguration">The project configuration.</param>
        public void SaveProject(ProjectConfiguration projectConfiguration)
        {
            ApplicationProject project = Projects.SingleOrDefault(x => x.ProjectPath == projectConfiguration.SaveFile);

            if (project != null)
            {
                ApplicationProject applicationProject = project;
                applicationProject.ProjectName = projectConfiguration.ProjectName;
                applicationProject.LastAccessTime = DateTime.Now;
            }
            else
            {
                Projects.Add(new ApplicationProject
                {
                    ProjectName = projectConfiguration.ProjectName,
                    ProjectPath = projectConfiguration.SaveFile,
                    LastAccessTime = DateTime.Now
                });
            }

            Save();
        }
    }
}